function NodeIterator(node, iterateRoot){
    if (!Utils.isDefined(node)) throw new CoreIMSEEException("Root node cannot be null");
    this.iterateRoot = Utils.isDefined(iterateRoot)?iterateRoot:false;
    this.root = node;   
    this.current = null;
    this.skipChildren = false;
}

NodeIterator.prototype.skipChildNodes = function () {
    this.skipChildren = true;
}

NodeIterator.prototype.nextSibling = function () {
    this.skipChildren = false;

    while (this.current!=this.root){
        if (this.current.nextSibling!=null) return (this.current=this.current.nextSibling);
        this.current = this.current.parentNode;
    }
    
    throw new CoreIMSEEException("Illegal operation");
}

NodeIterator.prototype.hasNextSibling = function () {
    var node = this.current;
    while (node!=this.root){
        if (node.nextSibling!=null) return true;
        node = node.parentNode;
    }
    return false;
}

NodeIterator.prototype.hasNext = function () {
    if (this.current==null) {
        return this.iterateRoot||this.root.hasChildNodes();              
    }
    
    if (this.current.hasChildNodes()&&!this.skipChildren) return true;
    return this.hasNextSibling();
}

NodeIterator.prototype.next = function () {
    if (this.current==null){
        if (this.iterateRoot) return (this.current = this.root);
        return (this.current = this.root.firstChild);
    }
    
    if (this.current.hasChildNodes()&&!this.skipChildren){
        return (this.current=this.current.firstChild);
    }
    
    return this.nextSibling();
}



